﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using RadarMonitor; 

namespace RadarMonitor
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private static System.Threading.Mutex mutex;

        private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            e.Handled = true;
        }

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            //Setting.Setting.Save();
            mutex = new System.Threading.Mutex(true, "RADMonitor_OnlyOneProcess");
            if (!mutex.WaitOne(0, false))
            {
                MessageBox.Show("RadarMonitor已经在运行", "提示");
                this.Shutdown();
            }
        }

        private void Application_Exit(object sender, ExitEventArgs e)
        {
            try { mutex.ReleaseMutex(); } catch { }
            Environment.Exit(0);
        }
    }
}
